/*
Copyright 2019 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

@import '../commons/index.css';

:root {
  --spectrum-tabs-item-height: calc(var(--spectrum-tabs-height) - var(--spectrum-tabs-rule-height));
  --spectrum-tabs-compact-item-height: calc(var(--spectrum-tabs-quiet-compact-height) - var(--spectrum-tabs-rule-height));
}

.spectrum-TabsPanel {
  display: flex;
  /* This is so TabsPanel can collapse with wrapping block/flex containers out of the box. If end user wants to place element next to tabpanel,
  they must include flex: 1 1 auto and min-width: 0 on the Tabs component. */
  width: 100%;
}

.spectrum-TabsPanel--horizontal {
  flex-direction: column;
}

.spectrum-TabsPanel--vertical {
  flex-direction: row;
}

.spectrum-Tabs {
  display: flex;

  /* Contain the selection indicator */
  position: relative;
  z-index: 0;

  margin: 0;
  padding: 0;

  /* Friends should align to the top of the tabs */
  vertical-align: top;

  outline: none;
  user-select: none;
}

.spectrum-Tabs-item {
  /* Contain the focus ring */
  position: relative;

  box-sizing: border-box;

  block-size: var(--spectrum-tabs-item-height);
  line-height: var(--spectrum-tabs-item-height);

  /* Float above the tab line */
  z-index: 1;

  text-decoration: none;
  white-space: nowrap;

  transition: color var(--spectrum-global-animation-duration-100) ease-out;
  cursor: default;
  outline: none;

  &[href] {
    cursor: pointer;
  }

  &.is-disabled {
    cursor: default;
  }

  .spectrum-Icon {
    /* Vertical centering */
    block-size: var(--spectrum-tabs-item-height);
    transition: fill var(--spectrum-global-animation-duration-100) ease-out;
    /* Prevents a wiggle in Safari when switching tabs. */
    transform: translate3d(0, 0, 0);

    & + .spectrum-Tabs-itemLabel {
      margin-inline-start: var(--spectrum-tabs-icon-gap);
    }
  }

  &::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;

    box-sizing: border-box;

    inset-inline-start: calc(var(--spectrum-tabs-focus-ring-padding-x) * -1);
    inset-inline-end: calc(var(--spectrum-tabs-focus-ring-padding-x) * -1);
    border: var(--spectrum-tabs-focus-ring-size) solid transparent;
    border-radius: var(--spectrum-tabs-focus-ring-border-radius);

    pointer-events: none;
  }
}

.spectrum-Tabs-itemLabel {
  vertical-align: top;
  display: inline-block;

  font-size: var(--spectrum-tabs-text-size);
  font-weight: var(--spectrum-tabs-text-font-weight);

  &:empty {
    /* Hide the tab label if it's not being used */
    display: none;
  }
}

.spectrum-Tabs-selectionIndicator {
  position: absolute;
  inset-inline-start: 0;

  /* Be below the tab */
  z-index: 0;
  transform-origin: top left;


  [dir='ltr'] .spectrum-Tabs--horizontal & {
    transform: translateX(var(--spectrum-tabs-focus-ring-padding-x));
  }

  [dir='rtl'] .spectrum-Tabs--horizontal & {
    transform: translateX(calc(var(--spectrum-tabs-focus-ring-padding-x) * -1));
  }

  border-radius: var(--spectrum-tabs-rule-border-radius);
}

.spectrum-Tabs--compact {
  .spectrum-Tabs-item {
    block-size: var(--spectrum-tabs-compact-item-height);
    line-height: var(--spectrum-tabs-compact-item-height);

    .spectrum-Icon {
      /* Vertical centering */
      block-size: var(--spectrum-tabs-compact-item-height);
    }
  }
}

.spectrum-Tabs--horizontal {
  align-items: center;

  border-block-end: var(--spectrum-tabs-rule-height) solid;

  .spectrum-Tabs-item {
    vertical-align: top;

    /* Target anything since React likes to add lots of happy <div>s around all things */
    & + *:not(.spectrum-Tabs-selectionIndicator) {
      margin-inline-start: var(--spectrum-tabs-item-gap);
    }

    &::before {
      top: 50%;
      bottom: unset;
      block-size: var(--spectrum-tabs-focus-ring-height);
      margin-block-start: calc(calc(var(--spectrum-tabs-focus-ring-height) / -2) + calc(var(--spectrum-tabs-rule-height) / 2));
    }
  }

  .spectrum-Tabs-selectionIndicator {
    position: absolute;
    block-size: var(--spectrum-tabs-rule-height);

    inset-block-end: calc(var(--spectrum-tabs-rule-height) * -1);
    transition: transform var(--spectrum-tabs-selection-indicator-animation-duration) ease-in-out, width var(--spectrum-tabs-selection-indicator-animation-duration) ease-in-out;
  }

  &.spectrum-Tabs--isCollapsed {
    inset-inline-start: 0;
    block-size: var(--spectrum-tabs-item-height);

    /* FieldButton Picker focus ring override */
    button {
      &::before {
        content: '';
        position: absolute;
        top: 50%;

        box-sizing: border-box;

        block-size: var(--spectrum-tabs-focus-ring-height);
        margin-block-start: calc(calc(var(--spectrum-tabs-focus-ring-height) / -2) + calc(var(--spectrum-tabs-rule-height) / 2));
        inset-inline-start: calc(var(--spectrum-tabs-focus-ring-padding-x) * -1);
        inset-inline-end: calc(var(--spectrum-tabs-focus-ring-padding-x) * -1);
        border: var(--spectrum-tabs-focus-ring-size) solid transparent;
        border-radius: var(--spectrum-tabs-focus-ring-border-radius);

        pointer-events: none;
      }
    }

    &.spectrum-Tabs--compact {
      button {
        height: calc(var(--spectrum-tabs-compact-item-height));
      }
    }
  }

  &.spectrum-Tabs--compact {
    /* The ActionButton is taller than the tabs, so don't push tabs around */
    box-sizing: content-box;
    block-size: var(--spectrum-tabs-compact-item-height);
    align-items: end;
  }
}

/* Quiet tabs should not extend all the way across the screen as their line doesn't */
.spectrum-Tabs--quiet {
  display: inline-flex;
}

.spectrum-Tabs--vertical {
  display: inline-flex;
  flex-direction: column;
  padding: 0;
  border-inline-start: var(--spectrum-tabs-vertical-rule-width) solid;

  .spectrum-Tabs-item {
    block-size: var(--spectrum-tabs-vertical-item-height);
    padding: 0 var(--spectrum-tabs-focus-ring-padding-x);
    /* Subtract focus ring padding from margin-left since the padding value already offsets tabs-items */
    margin-inline-start: calc(var(--spectrum-tabs-vertical-item-margin-left) - var(--spectrum-tabs-focus-ring-padding-x));
    margin-block-end: var(--spectrum-tabs-vertical-item-gap);

    &::before {
      /* padding is included in click area of tab items, so only need to offset by the size of the focus ring's border */
      inset-inline-start: calc(var(--spectrum-tabs-focus-ring-size) * -1);
      inset-inline-end: calc(var(--spectrum-tabs-focus-ring-size) * -1);
    }
  }

  /*
    Allow tab labels to wrap when TabList component has minWidth set.
  */
  &:not(.spectrum-Tabs--compact) .spectrum-Tabs-item {
    display: flex;
    align-items: center;
    white-space: normal;
    line-height: normal;
    block-size: auto;
    min-height: var(--spectrum-tabs-vertical-item-height);
  }

  &.spectrum-Tabs--compact {
    .spectrum-Tabs-item {
      block-size: var(--spectrum-tabs-compact-vertical-item-height);
      line-height: var(--spectrum-tabs-compact-vertical-item-height);
      margin-block-end: var(--spectrum-tabs-compact-vertical-item-gap);

      .spectrum-Icon {
        /* Vertical centering */
        block-size: var(--spectrum-tabs-compact-vertical-item-height);
      }
    }
  }

  .spectrum-Tabs-selectionIndicator {
    position: absolute;
    inline-size: var(--spectrum-tabs-vertical-rule-width);

    inset-inline-start: calc(var(--spectrum-tabs-vertical-rule-width) * -1);
    transition: transform var(--spectrum-tabs-selection-indicator-animation-duration) ease-in-out, height var(--spectrum-tabs-selection-indicator-animation-duration) ease-in-out;
  }
}

.spectrum-TabsPanel-collapseWrapper {
  display: flex;
  position: relative;
}

.spectrum-TabsPanel-tabs {
  flex-grow: 1;
  flex-shrink: 0;

  &.spectrum-Tabs--vertical {
    flex-grow: 0;
    min-width: min-content;
  }
}

.spectrum-TabsPanel-tabpanel {
  flex-grow: 1;
  border: var(--spectrum-tabs-focus-ring-size) solid transparent;
}

.spectrum-TabsPanel--vertical {
  .spectrum-Tabs {
    padding-right: var(--spectrum-global-dimension-size-160);
  }
}
